// Copyright 2017 Baidu Inc. All Rights Reserved.
// Author: Chen Xihao (chenxihao@baidu.com)
//
// Description: Base class of Media

#ifndef BAIDU_TINYDU_IOT_OS_SRC_MEDIA_BASE_BAIDU_MEDIA_BASE_H
#define BAIDU_TINYDU_IOT_OS_SRC_MEDIA_BASE_BAIDU_MEDIA_BASE_H

#include "mbed.h"
#include "baidu_recorder.h"
#include "baidu_media_type.h"

namespace duer {

class MediaBase : public Recorder::IPlugin {
public:
//// play
    int start_play(MediaType type);
    int write(const void* data, size_t size);
    int regulate_voice(unsigned char vol);
    int pause_play();
    int stop_play();
    bool is_play_stopped();
//// record pcm
    virtual int start_record();
    virtual size_t read(void* data, size_t size);
	virtual size_t read_done();
    virtual int stop_record();
//// record amr
	virtual int start_record_amr();
	virtual int stop_record_amr();
	virtual size_t read_amr(void* data, size_t size);

	virtual size_t setBtMode();
	virtual size_t setUartMode();
	virtual size_t SetName(const unsigned char* name);
//// 
protected:
    virtual int on_start_play(MediaType type) = 0;
    virtual int on_write(const void* data, size_t size) = 0;
    virtual int on_voice(unsigned char vol) = 0;
    virtual int on_pause_play() = 0;
    virtual int on_stop_play() = 0;
	virtual bool is_play_stopped_internal() = 0;

    virtual int on_start_record() = 0;
    virtual size_t on_read(void* data, size_t size) = 0;
	virtual size_t on_read_done() = 0;
    virtual int on_stop_record() = 0;

    virtual int on_start_record_amr() = 0;
    virtual int on_stop_record_amr() = 0;
	virtual size_t on_read_amr(void* data, size_t size) = 0;
	virtual int on_setBtMode()=0;
	virtual int on_setUartMode()=0;
	virtual size_t on_SetName(const unsigned char* name)=0;

private:
    static rtos::Mutex      _s_lock;
	static rtos::Mutex 		_s_record_lock;
    static int              _s_status;
};

} // namespace duer

#endif // BAIDU_TINYDU_IOT_OS_SRC_MEDIA_BASE_BAIDU_MEDIA_BASE_H
